#!/bin/bash
mkdir -p /data/prometheus/conf
cat > /data/prometheus/conf/prometheus.yml  <<EOF
global:
  scrape_interval:     15s # 采集数据的时间间隔,默认15s
  evaluation_interval: 15s # 评估规则的间隔时间,默认15s
alerting:     # alertmanagers用于告警
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093
rule_files:     # 规则配置文件
  # - ""first_rules.yml""
  # - ""second_rules.yml""
scrape_configs:    # 抓取哪里的数据到TSDB(时序数据库)
  - job_name: prometheus
    static_configs:
    - targets: ['localhost:9090']
  - job_name: docker
    static_configs:
    - targets: ['192.168.0.21:8080']

EOF
docker run --restart=always -p 9090:9090 -v /data/prometheus/conf/prometheus.yml:/etc/prometheus/prometheus.yml -v /data/prometheus/data:/prometheus -d prom/prometheus